package com.oceansoft.mobile.econsole.common.spring;


import com.oceansoft.mobile.econsole.modules.dcn.DataChangeNotificationListener;
import com.oceansoft.mobile.econsole.modules.dcn.processor.OuterCoreProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * ClassName: DataListener
 * Desc: 数据库数据监听器 DCN
 * Date： 2016/11/16
 * Created：shaom
 */
public class DataListener implements ServletContextListener {
    private static final Logger log = LoggerFactory.getLogger(DataListener.class);
    private DataChangeNotificationListener dataChangeNotificationListener;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        log.info("开始启动Oracle数据库监听...");
        dataChangeNotificationListener = SpringContextHolder.getBean("dataChangeNotificationListener");
        OuterCoreProcessor outerCoreProcessor = SpringContextHolder.getBean("outerCoreProcessor");
        dataChangeNotificationListener.listening(outerCoreProcessor);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        log.info("取消oracle数据监听........");
        dataChangeNotificationListener.stopListening();
    }
}
